Transfer Mode Types
Transfer modes can be specified by type, also called component mode. Transfer mode types in QuickDraw GX are called component modes because QuickDraw GX allows each color component to have its own transfer mode type. In RGB color space, for example, the red component of the color may be drawn with a different transfer mode type than the blue component.QuickDraw GX supports several conceptual categories of component modes:
The characteristics of and most typical uses for the component modes within each category are summarized in the following subsections.
- arithmetic
- Boolean
- pseudo-Boolean
- highlight
- alpha-channel
- Copy mode is the default
- Even though QuickDraw GX supports 18 different component modes, most applications in most situations need only one, an arithmetic mode called copy mode. In copy mode, the source color completely replaces the destination color. Copy mode is the default transfer mode in QuickDraw GX; therefore, you need information about other transfer modes only if you want them for special effects.
![]()
Arithmetic Transfer Modes
In arithmetic transfer modes, the numerical values of source and destination for a color component are combined arithmetically to determine the result value for that color component. In most color spaces, a color component value can vary from 0 (no intensity) to 0xFFFF (maximum intensity). You can also use the constantgxColorValue1
to represent maximum intensity (0xFFFF).Figure 5-2 shows examples of drawing with the arithmetic transfer modes. In each case, the source image (left) combines with the destination image (center) to produce the result image (right). You can think of the images either as two bitmaps, or as two source shapes (cloud and background) that are drawn over two destination shapes (letter and background).
Each example shows how transfer mode affects drawing within a single color component (reflected as shades of gray in the figure, where black equals 0 and white equals 0xFFFF). The constant that specifies the transfer mode type is shown to the right of each example. Note also that two of the arithmetic transfer modes use an operand, a numerical value that affects the outcome of the transfer-mode operation.
Figure 5-2 Arithmetic transfer modes
The constants that define transfer mode type are defined in the gxComponentModes enumeration. The arithmetic modes have the following values and meanings:
Constant Value Explanation gxNoMode 0 No mode. No transfer occurs. For this component of
the color, the destination is left as it was. This mode is
useful for suppressing drawing when certain logical conditions are met, or for not drawing one color component while allowing other components to be drawn.gxCopyMode 1 Copy mode. The source color component is copied to
the destination. The destination component is ignored. This is the most common transfer mode, and is the default for QuickDraw GX.gxAddMode 2 Add mode. The source color component is added to
the destination component, but the result is not
allowed to exceed the maximum value (0xFFFF orgxColorValue1
; white in Figure 5-2).gxBlendMode 3 Blend mode. The result is the average of the source
and destination color components, weighted by a ratio specified by the operand component (0.5 in Figure 5-2). The operand varies from 0 (all destination) to 0xFFFF orgxColorValue1
(all source), although it is customary to interpret it as varying between 0 and 1.gxMigrateMode 4 Migrate mode. The destination color component is moved toward the source component by the value of
the step specified in the operand component (0.25, or 0x4000 in Figure 5-2). Migrate mode is similar to blend mode, except that the change in destination component is an absolute amount, rather than a proportion of the difference between it and the source component. If the source has a greater color component value than the destination, the migration is positive; if the destination has a greater value than the source, the migration is negative. In either case, the amount of migration cannot be greater than the difference between the destination and the source values.gxMinimumMode 5 Minimum mode. The source component replaces the
destination component only if the source component
has a smaller value. (In Figure 5-2, drawing occurs only within the area occupied by the cloud.)gxMaximumMode 6 Maximum mode. The source component replaces the
destination component only if the source component
has a larger value. (In Figure 5-2, drawing occurs only outside of the area occupied by the cloud.)The
operand
parameter is used by blend mode to specify the ratio of source and destination component. It is used by migrate mode to specify the step size by which the destination component moves toward the source component. Figure 5-3 shows examples of the result of drawing with blend mode, using several different values for the operand. (Color Plate 1 at the front of this book shows the same example in color.)Figure 5-3 Blend example with different operand values
Highlight Transfer Mode
The highlight transfer mode is used for highlighting in color applications. It is most commonly used to draw (and clear) a colored rectangle around a selection, without altering the color of the item or items selected. In text, it gives the effect of drawing over the letters with a highlighting pen.Like some of the arithmetic transfer modes, highlight mode uses an operand to control the outcome of the highlighting operation. Highlight mode operates by replacing the source color with the operand color, and the operand color with the source color, in the destination.
The upper row of images in Figure 5-4 shows a simple example of the application of highlight mode. The operand value is represented with shading rather than as a number, to illustrate how its color affects colors in the image. The source shape is a white rectangle that is drawn over the two middle letters in the destination image. (The gray letters in the line of text in the destination image represent the same color-component value as the operand, and the white area around the letters in the destination represents the same color-component value as the source.)
Figure 5-4 Highlight transfer mode
Note that black in the destination is unaffected, whereas white becomes gray and gray becomes white. A single constant specifies highlight mode, with the following value and meaning:
Constant Value Explanation gxHighlightMode 7 Highlight mode. The source component and operand component are swapped in the destination. Other components in the destination are ignored. In highlight mode, the source color can be thought of as the "background" color that is to be highlighted, and the operand color is the color of the highlighting pen. As the lower set of images in Figure 5-4 shows, redrawing a highlighted selection causes the source and operand colors to swap once more, effectively removing the highlighting.
The operand for highlight mode is a normal color component value that varies from 0 (no intensity) to the maximum intensity permitted for that component (normally 0xFFFF, or
gxColorValue1
).QuickDraw GX applies highlight mode only if all components in the color space specify it. An error occurs if some components specify highlight mode and others do not.
Boolean Transfer Modes
In Boolean transfer modes, the result value for a color component is determined by bit operations performed on the source and destination component values. Boolean transfer modes are most common in black-and-white drawing; in any bit depth other than 1, they yield results that can be difficult to predict because they depend on the states of the individual bits in each color-component value.Figure 5-5 shows examples of drawing with the Boolean transfer modes at a bit depth of 1. In each case, the source image combines with the destination image to produce the result image. In these examples, black represents a bit value of 0 (clear), and white represents a bit value of 1 (set). The constant that specifies the transfer mode type is shown to the right of each example.
Figure 5-5 Boolean transfer modes (1-bit depth)
The Boolean modes have the following values and meanings:
Even though they are most easily explained in terms of single-bit depths, Boolean
modes are not restricted to 1-bit drawing. They can be used with any kind of color values, and are useful for manipulating colors in an indexed color space.Pseudo-Boolean Transfer Modes
In pseudo-Boolean transfer modes, the result value for a color component is determined by normalizing the source and destination values and performing a simple arithmetic operation, to achieve consistent and predictable results analogous to 1-bit Boolean operations.Figure 5-6 shows examples of drawing with the pseudo-Boolean transfer modes. In each case, the source image combines with the destination image to produce the result image. The constant that specifies the transfer mode type is shown to the right of each example.
Figure 5-6 Pseudo-Boolean transfer modes
The constants for the pseudo-Boolean component modes have the following values and meanings:
Note that the pseudo-Boolean and Boolean modes are similar in several ways:
The difference between the pseudo-Boolean and Boolean modes is that, for multi-bit pixel depths, the results for
- The mode
gxRampAndMode
is similar togxAndMode
in that nonzero values occur in the result only where both source and destination are nonzero.- The mode
gxRampOrMode
is similar togxOrMode
in that nonzero values occur in the result wherever either the source or the destination is nonzero.- The mode
gxRampXorMode
is similar togxXorMode
in that the result is close to zero wherever the source and destination are close to each other in value.
gxRampAndMode
,gxRampOrMode
, andgxRampXorMode
are predictable and vary smoothly and continuously with component intensity. For 1-bit depths, these modes are identical to their Boolean equivalents.The pseudo-Boolean modes are commonly used as component modes for alpha channels in color spaces that have an alpha channel. See "Alpha-Channel Transfer Modes" (next).
Alpha-Channel Transfer Modes
Several QuickDraw GX color spaces (gxRGBASpace
,gxARGB32Space
andgxGrayASpace
) have an alpha channel. This is an additional color component that controls the opacity or transparency of a color. For example, a red pixel in a source image can be completely opaque, in which case it typically retains its red color when drawn over a blue pixel in the destination image. Or, the pixel can be completely transparent, in which case it typically loses all its color and turns totally blue when drawn over a blue pixel. Or, it can have an opacity of, say, 0x7FFF (50%), in which case it typically turns magenta when drawn over a blue pixel.Alpha channel values can be used to allow parts of one image to show through "holes" in another, to show translucency in objects that are drawn over other objects, and to perform anti-aliasing (smoothing of jagged edges) by giving feathered, semi-transparent borders to opaque objects.
When assigning transfer modes to colors with an alpha channel, you typically use two different kinds of modes:
This section describes how the different modes within each category work to give you the results you want.
- To get the proper result color for each color component, you use an alpha-channel transfer mode. These modes take alpha-channel values into account when calculating result values for the color components.
- To get the proper result opacity for the alpha channel itself, you typically use an arithmetic or pseudo-Boolean transfer mode.
Modes for the Color Components
Figure 5-7 shows examples of how values for a color component might be calculated, given a source image and a destination image consisting of objects (or pixels) that differ in opacity. In each example, the source image (an opaque, light gray cloud against a transparent black background) combines with the destination image (an opaque, dark gray "A" on a transparent black background), to form the result image. The constant that specifies the transfer mode type is shown to the right of each example.Each example shows how the alpha-channel transfer mode affects drawing within a single color component. The mode takes into account not only the source and destination color components, but the source and destination opacities as well.
Figure 5-7 Alpha-channel transfer modes
The constants for the alpha-channel component modes have the following values and meanings:
As Figure 5-7 shows, the
gxOverMode
mode is similar to the arithmetic transfer modegxCopyMode
, except that it allows for transparency in the source image. Likewise, thegxAtopMode
mode is similar togxCopyMode
, but it preserves the transparency of
the destination image by clipping the opaque source to the destination image. ThegxExcludeMode
mode is somewhat like the Boolean transfer modegxXorMode
, in
that opaque parts of each image appear only where the other is not opaque. ThegxFadeMode
mode is like the arithmeticgxBlendMode
, except that the operand that controls the blend ratio is determined by the relative opacities.Note that the images shown in Figure 5-7 are very simple and their opacities are either 0 (completely transparent) or
gxColorValue1
(completely opaque). Because an alpha component can have a wide range of partial opacities, very sophisticated translucency and color-blending effects are possible, as well as the simple masking effects shown here.The exact formulas for determining result color are the following. In these
formulas,sA
= source alpha-channel value;dA
= destination alpha-channel value;sC
= source color-component value;dC
= destination color-component value;
andrC
= result color-component value.
- For
gxOverMode
:
rC = (sAx
(sC-
dAx
dC)+
dAx
dC)/
(sA+
dA-
sAx
dA)- For
gxAtopMode
:
rC = dC+
sAx
(sC-
dC)- For
gxExcludeMode
:
rC = (sAx
sC+
dAx
dC-
sAx
dAx
(sC+
dC))/
(sA+
dA-
sAx
dA)- For
gxFadeMode
:
rC = sAx
sC+
dAx
dC/
(sA+
dA)
Modes for the Alpha Channel
For calculating the result value for the alpha channel itself, you typically use one of the arithmetic or pseudo-Boolean transfer modes presented in the previous sections--one that takes into account only the source and destination opacities. Figure 5-8 shows typical modes used and their effects on opacity, using the same images is those presented in Figure 5-7. In this figure, black represents complete transparency and white represents complete opacity. (If alpha-channel values between the two extremes existed in these examples, they would be shown in shades of gray.)Figure 5-8 Typical modes used to determine result opacity for the alpha channel
Note from Figure 5-8 that the mode you use to determine the result opacity of the alpha channel usually depends on what alpha-channel mode you use to get color-component values:
- Use
gxRampOrMode
to calculate result alpha-channel values if you want the opacities of both source and destination summed proportionally (in a pseudo-Boolean manner; see the description ofgxRampOrMode
on page 5-19) to achieve a result opacity. Thus, if you usegxOverMode
for the color-components, you would typically usegxRampOrMode
for the alpha channel.- Use
gxNoMode
to calculate result alpha-channel values if you want the opacity of the destination to remain unchanged. Thus, if you usegxAtopMode
for the color-components, you would typically usegxNoMode
for the alpha channel.- Use
gxRampXorMode
to calculate result alpha-channel values if you want a maximum result opacity where there is a maximum difference in opacities between source and destination. Thus, if you usegxExcludeMode
for the color-components, you would typically usegxRampXorMode
for the alpha channel.- Use
gxAddMode
to calculate result alpha-channel values if you want the result opacity to reflect the sum of the opacities of the source and destination (pinned to the maximum permitted value). Thus, if you usegxFadeMode
for the color-components, you would typically usegxAddMode
for the alpha channel.
- Note
- When converting a color from a color space that does not have an alpha channel to one that does, QuickDraw GX sets the alpha channel intensity to maximum (opaque). When a color is converted from a color space that does have an alpha channel to one that does not, the alpha channel is lost.
![]()
Transparency Ramps and Anti-Aliasing
Two common applications for alpha-channel colors involve making objects or images partially opaque to give a translucent effect, and smoothing jagged edges on objects drawn at low resolution.You can create a bitmap in which the alpha-channel values of the pixels vary smoothly in one or more directions, thus creating a transparency ramp that allows the destination image to show through the source image to varying degrees across the bitmap. Color Plate 2 at the front of this book, for example, shows the kind of effect that can be achieved with a simple alpha-channel ramp.
The smoothing of jagged edges on displayed objects is called anti-aliasing. You can perform anti-aliasing by modifying the alpha-channel values of the pixels surrounding the edges of an opaque object. You make an individual pixel more or less opaque, based on the proportion of that pixel that the object is computed to cover.
In Figure 5-9, for example, the left image shows the computed position of the edge of a shape in a bitmap. The center image shows how that edge is displayed normally, given the resolution of the bitmap. The right image shows that edge as it might be displayed with anti-aliasing applied. The apparent jaggedness is decreased because pixels near the edge allow the background to show through to varying degrees.